<template>
    <v-layout type="main">
        <div class="alike-lis-header">
            <div class="lis-header-left">
                <div class="search-box">
                    <el-input prefix-icon="el-icon-search" v-model="Pagedata.name" class="search" placeholder=""
                        @input="getData" />
                </div>
            </div>

            <div class="lis-header-right">
                <el-select size="mini" placeholder="请选择" v-model="showThisActive" @change="getData">
                    <el-option label="数据集" value="0"></el-option>
                    <el-option label="算法" value="1"></el-option>
                    <el-option label="模型" value="2"></el-option>
                </el-select>
            </div>
        </div>


        <el-table v-if="showThisActive == 0" :data="tableData">
            <el-table-column prop="name" label="名称">
                <template slot-scope="{ row }">
                    <el-popover placement="right-start" width="320" trigger="hover">
                        <row-data :row="row" />
                        <el-button type="text"
                            @click="$router.push({ path: '/market/code', query: { id: row.id, active: 0 } })"
                            slot="reference">{{ row.name }}</el-button>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="alias" label="别名" />
            <el-table-column prop="file_type" label="类型" />
            <el-table-column prop="create_user.username" label="发布人" />
            <el-table-column prop="create_time" label="发布时间" />
            <el-table-column prop="name" label="操作">
                <template slot-scope="{ row }">
                    <el-button type="text" @click="pass(row.id)">通过</el-button>
                    <el-button type="text" @click="deny(row.id)">不通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-table v-if="showThisActive == 1" :data="tableData">
            <el-table-column label="名称">
                <template slot-scope="{ row }">
                    <el-popover placement="right-start" width="320" trigger="hover">
                        <row-data :row="row" />
                        <el-button type="text"
                            @click="$router.push({ path: '/market/code', query: { id: row.algorithm.id, version_id: row.id, active: 1 } })"
                            slot="reference">{{ row.algorithm.name }}</el-button>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="version" label="版本" />
            <el-table-column prop="commit" label="提交信息" />
            <el-table-column prop="create_user.username" label="发布人" />
            <el-table-column prop="create_time" label="发布时间" />
            <el-table-column prop="name" label="操作">
                <template slot-scope="{ row }">
                    <el-button type="text" @click="pass(row.id)">通过</el-button>
                    <el-button type="text" @click="deny(row.id)">不通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-table v-if="showThisActive == 2" :data="tableData">
            <el-table-column label="名称">
                <template slot-scope="{ row }">
                    <el-popover placement="right-start" width="320" trigger="hover">
                        <row-data :row="row" />
                        <el-button type="text"
                            @click="$router.push({ path: '/market/code', query: { id: row.model.id, version_id: row.id, active: 2 } })"
                            slot="reference">{{ row.model.name }}</el-button>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column prop="version" label="版本" />
            <el-table-column prop="commit" label="提交信息" />
            <el-table-column prop="create_user.username" label="发布人" />
            <el-table-column prop="create_time" label="发布时间" />
            <el-table-column prop="name" label="操作">
                <template slot-scope="{ row }">
                    <el-button type="text" @click="pass(row.id)">通过</el-button>
                    <el-button type="text" @click="deny(row.id)">不通过</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-box" v-if="Pagedata.total > Pagedata.pageSize">
            <el-pagination background class="pagination" layout="total, prev, pager, next, jumper"
                :page-size="Pagedata.pageSize" :current-page.sync="Pagedata.pageNum" @current-change="handleCurrentChange"
                :total="Pagedata.total">
            </el-pagination>
        </div>
    </v-layout>
</template>
  
<script>
import { geAuditAlgorithmVersions, passAlgorithmVersion, denyAlgorithmVersion } from '@/api/market'
import { geAuditModelVersions, passModelVersion, denyModelVersion } from '@/api/market'
import { geAuditatasets, passDataset, denyDataset } from '@/api/market'
export default {
    data() {
        return {
            tableData: [],
            showThisActive: "0",
            Pagedata: {
                pageNum: 1,
                pageSize: 10,
                total: 0,
                name: "", // 名称搜索
                order: "create_time", // 排序recommend、createTime、likeCount
            },
        };
    },
    async created() {
        this.getData()
    },
    methods: {
        async getData() {
            if (this.showThisActive == 0) {
                let res = await geAuditatasets({ visibility: 2, ...this.Pagedata })
                this.tableData = res.data.list
                this.Pagedata.total = res.data.total
            } else if (this.showThisActive == 1) {
                let res = await geAuditAlgorithmVersions({ visibility: 2, ...this.Pagedata })
                this.tableData = res.data.list
                this.Pagedata.total = res.data.total
            } else if (this.showThisActive == 2) {
                let res = await geAuditModelVersions({ visibility: 2, ...this.Pagedata })
                this.tableData = res.data.list
                this.Pagedata.total = res.data.total
            }

        },
        handleCurrentChange() {
            this.getData()
        },
        async deny(id) {
            if (this.showThisActive == 0) {
                await denyDataset(id)
            }
            if (this.showThisActive == 1) {
                await denyAlgorithmVersion(id)
            }
            if (this.showThisActive == 2) {
                await denyModelVersion(id)
            }
            this.getData()
        },
        async pass(id) {
            if (this.showThisActive == 0) {
                await passDataset(id)
            }
            if (this.showThisActive == 1) {
                await passAlgorithmVersion(id)
            }
            if (this.showThisActive == 2) {
                await passModelVersion(id)
            }
            this.getData()
        }
    }
}
</script>
<style lang="less" scoped>
.alick-handle {
    position: absolute;
    right: 16px;
    top: 50px;
    padding: 0;
    width: 280px;
}
</style>